package com.gzhryc.shared_device.oem.code.agent.dao;

import com.gzhryc.jdbc.BaseDao;
import com.gzhryc.jdbc.Conditions;
import com.gzhryc.jdbc.Query;
import com.gzhryc.shared_device.oem.code.agent.dao.db.AgentRelationFuncModel;
import com.gzhryc.shared_device.oem.code.agent.dao.models.RelationUserFuncModelCount;

import java.sql.SQLException;
import java.util.List;

public class AgentRelationFuncModelDao extends BaseDao<AgentRelationFuncModel> {

    public AgentRelationFuncModelDao(String jdbcKey){
        super(jdbcKey);
    }

    public List<RelationUserFuncModelCount> countGroupRelationUserId(Conditions conditions) throws SQLException {
        String sql = "SELECT relation_user_id AS relationUserId,COUNT(1) AS funcModelCount FROM " + this.tableName;
        Query query = new Query(sql);
        query.appendSql(conditions.toSql(query.getParams(),true));
        query.appendSql(" GROUP BY relation_user_id");
        return this.jdbcHelper.find(query,RelationUserFuncModelCount.class);
    }
}
